<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="../css/weui.css"/>
    <link rel="stylesheet" href="../css/weuix.css"/>

    <script src="../js/zepto.min.js"></script>
    <script src="../js/zepto.weui.js"></script>
    <script>
        $(function(){
               $(document).on("click","#btn",function(){
                   var user = $("#user").val();
                   if(user==""){
                       $.toptip("用户名不能为空");
                       return false;
                   }else{
                       $.toptip("提交成功",'success');
                   }
               })
			   //解决表单控件不能回弹 只有微信ios有这个问题
           $("input,select,textarea").blur(function(){
setTimeout(() => {
const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
window.scrollTo(0, Math.max(scrollHeight - 1, 0));
}, 100);
})    
  $(document).on('change','#select2',function(){
let val=$(this).val()
alert(val)
let val1=$(this).find('option:selected').text()
alert(val1)
})
        });
        
        var countdown=60;

        function settime(obj) {

            var code = $(obj);
            if (countdown == 0) {
                code.removeAttr('disabled');
                code.text("获取验证码");
                countdown =60;
                return;
            } else {
                code.text("重新发送(" + countdown + ")");
                code.attr('disabled',true);
                countdown--;
            }
            setTimeout(function() {
                settime(obj) }, 1000);

        }
        getcode()
        function getcode(){
            $.get("/code?random="+Math.random(),function(res){
                $("#code").attr("src",res.img);
            },'json');

        };

        function textarea(input) {
            var content = $(input);
              var max =  content.next().find('i') .text();
            var value = content.val();
            if (value.length>0) {

                value = value.replace(/\n|\r/gi,"");
                var len = value.length;
                content.next().find('span').text(len) ;
                 if(len>max){
                     content.next().addClass('f-red');
                 }else{
                     content.next().removeClass('f-red');
                 }
            }
        }

        function cleartxt(obj){
            $(obj).prev().find('.weui-input').val("");
            return false;
        }

        function cleararea(obj){
            $(obj).prev().find('.weui-textarea').val("").next().find("span").text(0);
            return false;
        }

    </script>
</head>

<body ontouchstart>
<div class="page-hd">
    <h1 class="page-hd-title">
        文本框/文本域/倒计时和图形验证码/验证表单
    </h1>
    <p class="page-hd-desc"></p>
</div>

<div class="weui-cells__title">表单</div>

<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">number</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" pattern="[0-9]*" placeholder="请输入qq号" type="number">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label">手机号</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="请输入手机号" type="tel">
        </div>

    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label class="weui-label">验证码</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="验证码" type="number">
        </div>
        <div class="weui-cell__ft">
            <button  class="weui-vcode-btn" onclick="settime(this)">获取验证码</button>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">date</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" value="" type="date">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">datetime</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" value="" placeholder="" type="datetime-local">
        </div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd"><label class="weui-label">验证码</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="请输入验证码" type="number">
        </div>
        <div class="weui-cell__ft">
            <img id="code" class="weui-vcode-img" src="/code" width="130" height="53" onclick="getcode();">
        </div>
    </div>
</div>

<div class="weui-cells__tips">底部说明文字底部说明文字</div>

<div class="weui-cells weui-cells_form">
    <div class="weui-cell weui-cell_warn">
        <div class="weui-cell__hd"><label class="weui-label">卡号</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" pattern="[0-9]*" value="weui input error" placeholder="请输入卡号" type="number">
        </div>
        <div class="weui-cell__ft">
            <i class="weui-icon-warn"></i>
        </div>
    </div>
</div>

<div class="weui-cells">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="请输入文本" type="text">
        </div>
    </div>
</div>

<div class="weui-cells">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="清除文本" type="text">
        </div>
        <i class="weui-icon-clear" onclick="cleartxt(this)"></i>
    </div>
</div>

<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea class="weui-textarea" placeholder="请输入文本" rows="3" onkeyup="textarea(this);"></textarea>
            <div class="weui-textarea-counter"><span>0</span>/<i>10</i></div>
        </div>
        <i class="weui-icon-clear" onclick="cleararea(this)"></i>
    </div>
</div>

<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <textarea class="weui-textarea" placeholder="请输入文本" rows="3" onkeyup="textarea(this);"></textarea>
            <div class="weui-textarea-counter"><span>0</span>/<i>10</i></div>
        </div>
    </div>
</div>

<div class="weui-cells">

    <div class="weui-cell weui-cell_select weui-cell_select-before">
        <div class="weui-cell__hd">
            <select class="weui-select" name="select2">
                <option value="1">+86</option>
                <option value="2">+80</option>
                <option value="3">+84</option>
                <option value="4">+87</option>
            </select>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" pattern="[0-9]*" placeholder="请输入号码" type="number">
        </div>
    </div>
</div>

<div class="weui-cells">
    <div class="weui-cell weui-cell_select">
        <div class="weui-cell__bd">
            <select class="weui-select" name="select1">
                <option selected="" value="1">微信号</option>
                <option value="2">QQ号</option>
                <option value="3">Email</option>
            </select>
        </div>
    </div>
    <div class="weui-cell weui-cell_select weui-cell_select-after">
        <div class="weui-cell__hd">
            <label for="" class="weui-label">国家/地区</label>
        </div>
        <div class="weui-cell__bd">
            <select class="weui-select" name="select2" id="select2">
                <option value="1">中国</option>
                <option value="2">美国</option>
                <option value="3">英国</option>
            </select>
        </div>
    </div>
</div>

<label for="weuiAgree" class="weui-agree">
    <input id="weuiAgree" class="weui-agree__checkbox" type="checkbox">
    <span class="weui-agree__text">
                阅读并同意<a href="javascript:void(0);">《相关条款》</a>
            </span>
</label>

<div class="weui-cells">
    <div class="weui-cell">
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="用户名" type="text" id="user" >
        </div>
    </div>
</div>

<div class="weui-btn-area">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="btn">确定</a>
</div>


<br>
<br>

<div class="weui-footer weui-footer_fixed-bottom">
    <p class="weui-footer__links">
        <a href="../index.html" class="weui-footer__link">WeUI首页</a>
    </p>
    <p class="weui-footer__text">Copyright &copy; Yoby</p>
</div>
</body>
</html>